// pages/Main/mainIndex/mainIndex.js 
var common = require('../../../utils/common.js')
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orgid:"",
    userid:"",
    examid:"",
    testid:"",
    infodata: [],
    extype:"",
    parid:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let c = common.Getorgid();
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      examid: options.examid,
      extype: options.type,
      parid: options.parid
    });
    this.studetall();

  },
  //8.5.2  查询考试试卷内容 
  studetall: function () {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "id": this.data.parid, }
    businessLogic.QueryTestC(params, (res) => {
     console.log("8.5.2", res)
      this.setData({
        infodata: res.papercontent
      })
      this.answersay();
    })
  },
  //8.5.3 查询考试试卷答案评语
  answersay: function () {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "peopleid,examid", "searchValue": this.data.userid + "," + this.data.examid + "," }
    businessLogic.QueryTestAnswer(params, (res) => {
     console.log("8.5.3", res)
      this.setData({
        listdata: res
      })
      for (var k = 0; k < this.data.listdata.length; k++) {
        for (var i = 0; i < this.data.infodata.length; i++) {
          for (var j = 0; j < this.data.infodata[i].qt.length; j++) {
            if (this.data.infodata[i].qt[j].typecode == '1ab96071-3741-40b7-983c-bba5a031fe0d') {
              for (var m = 0; m < this.data.infodata[i].qt[j].csub.length; m++) {
                if (this.data.infodata[i].qt[j].csub[m].id == this.data.listdata[k].testid) {
                  this.data.infodata[i].qt[j].csub[m].say = this.data.listdata[k].say;
                  this.data.infodata[i].qt[j].csub[m].point = this.data.listdata[k].point;
                }
              }
            }
            else {
              if (this.data.infodata[i].qt[j].id == this.data.listdata[k].testid) {
                this.data.infodata[i].qt[j].say = this.data.listdata[k].say;
                this.data.infodata[i].qt[j].point = this.data.listdata[k].point;
              }
            }
          }
        }
      }
      this.setData({
        newdata: this.data.infodata
      })
      console.log(this.data.newdata)
    })
  },
 testDet: function () { 
    if(this.data.extype=="已批改"){
         wx.navigateTo({
           url: "../answeron/answeron?title=试卷详情&&examid=" + this.data.examid + "&&remarktype=3&&examtype=0&&parid=" + this.data.parid
        });

    } else if (this.data.extype == "未批改"){
      wx.navigateTo({
        url: "../answeron/answeron?title=试卷详情&&examid=" + this.data.examid + "&&remarktype=4&&examtype=0&&&parid=" + this.data.parid
      });
    }
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})